<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
class dropzone extends admin {
	public $siteid,$categorys;
	function __construct() {
		parent::__construct();
		$this->M = new_html_special_chars(getcache('dropzone', 'commons'));
		$this->db = pc_base::load_model('dropzone_model');
		$this->db2 = pc_base::load_model('type_model');
	}

	public function init() {
		$where = array('siteid'=>$this->get_siteid());
		$this->siteid = $this->get_siteid();
		pc_base::load_sys_class('form', '', 0);
		$r = $this->db->get_one(array());
		include $this->admin_tpl('dropzone_add');
	}

	public function add() {
 		if(isset($_POST['dosubmit'])) {
			$_POST['dropzone']['siteid'] = $this->get_siteid();
			if(empty($_POST['dropzone']['img_path'])) {
				showmessage(L('img_path_noempty'),HTTP_REFERER);
			} else {
				$_POST['dropzone']['img_path'] = safe_replace($_POST['dropzone']['img_path']);
			}
			if ($_POST['dropzone']['link']) {
				$_POST['dropzone']['link'] = safe_replace($_POST['dropzone']['link']);
			}
			if ($_POST['dropzone']['isuse']) {
				$_POST['dropzone']['isuse'] = safe_replace($_POST['dropzone']['isuse']);
			}
			if ($_POST['dropzone']['type']) {
				$_POST['dropzone']['type'] = safe_replace($_POST['dropzone']['type']);
			}
			if ($_POST['dropzone']['dropzoneid']) {
				//update
				$_POST['dropzone']['dropzoneid'] = safe_replace($_POST['dropzone']['dropzoneid']);
				$this->db->update($_POST['dropzone'],array('dropzoneid'=>$_POST['dropzone']['dropzoneid'] ));
			}else{
					//insert
					$data = new_addslashes($_POST['dropzone']);
					$dropzoneid = $this->db->insert($data,true);
					if(!$dropzoneid) return FALSE; 
			}
 			$siteid = $this->get_siteid();
	 		//更新附件状态
			if(pc_base::load_config('system','attachment_stat') & $_POST['dropzone']['img_path']) {
				$this->attachment_db = pc_base::load_model('attachment_model');
				$this->attachment_db->api_update($_POST['dropzone']['img_path'],'dropzone-'.$dropzoneid,1);
			}
				showmessage(L('operation_success'),'?m=dropzone&c=dropzone&a=init',1250,'', 'add');
		} else {
				$this->init();
		}

	}
}
?>